typedef struct 
{
    int* arr;
    int rear;
    int front;
    int k;
} MyCircularQueue;

bool myCircularQueueIsEmpty(MyCircularQueue* obj);
bool myCircularQueueIsFull(MyCircularQueue* obj);
MyCircularQueue* myCircularQueueCreate(int k) 
{
    MyCircularQueue* temp = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    temp->k=k;
    temp->arr = (int*)malloc(sizeof(int)* (k+1));
    temp->rear =0;
    temp->front = 0;
    
    return temp;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) 
{
    if(myCircularQueueIsFull(obj))
    {
        return false;
    }
    obj->rear %= obj->k+1;
    obj->arr[obj->rear++] = value;
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) 
{
    if(myCircularQueueIsEmpty(obj))
    {
        return false;
    }
    obj->front++;
    obj->front = obj->front == obj->k+1 ?0:obj->front;

    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) 
{
    if(myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    return obj->arr[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj) 
{
    if(myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    int rear = obj->rear == 0? obj->k:obj->rear-1;
    return obj->arr[rear];
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) 
{
    return obj->front == obj->rear;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) 
{
    if(obj->front == (obj->rear+1) % (obj->k+1))
    {
        return true;
    }
    return false;
}

void myCircularQueueFree(MyCircularQueue* obj) 
{
    free(obj->arr);
    free(obj);
}